package com.heima.article.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heima.article.entity.ApArticle;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heima.model.article.dtos.ArticleDto;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 文章信息表，存储已发布的文章 Mapper 接口
 * </p>
 *
 * @author HM
 * @since 2023-02-15
 */
public interface ApArticleMapper extends BaseMapper<ApArticle> {


    @Select("select  a.*,b.content as content from ap_article a,ap_article_content b " +
            "  where b.article_id  = a.id and a.is_down=0 and a.is_delete=0")
    List<ArticleDto> selectArticleAndContent(IPage<ArticleDto> ipage);


    /**
     * 根据文章id 查询文章对象
     * @param articleId
     * @return
     */
    @Select("select  a.*,b.content as content from ap_article a,ap_article_content b " +
            " where a.id=#{articleId} and b.article_id  = a.id and a.is_down=0 and a.is_delete=0")
    ArticleDto selectArticleAndContentById(Long articleId);
}
